<?php
    class Sort_model extends CI_Model {

        function __construct()
        {
            parent::__construct();
        }


		  function get_sort_by_id($id)
        {
            $sql="SELECT id, name, pid, path, CONCAT( path, '-', id ) AS bpath FROM crazy_sort where id in($id) ORDER BY bpath";
            return $this->db->query($sql);
        }
		
		

        function get_sort_all()
        {
            $sql="SELECT id, name, pid, path, CONCAT( path, '-', id ) AS bpath FROM crazy_sort ORDER BY bpath";
            return $this->db->query($sql);
        }

        //根据父ID获取子类列表
        function get_sort_by_pid($pid=0)
        {
            return $this->db->from('crazy_sort')->where('pid',$pid)->get();
        }

        //根据ID获取一条记录
        function get_sort_by_id_one($id)
        {
            return $this->db->from('crazy_sort')->where('id',$id)->get()->row();

        }
        //根据获取一条记录
        function get_sort_by_name_one($name)
        {
            return $this->db->from('crazy_sort')->where('name',$name)->get()->row();

        }

        //新增分类
        function get_sort_add($data)
        {
            $this->db->insert('crazy_sort', $data); 

        }

        //编辑分类
        function get_sort_modify($id,$data)
        {
            $this->db->where('id', $id);
            $this->db->update('crazy_sort', $data); 
        }

        //删除分类
        function get_sort_del($id)
        {
            $this->db->where('id', $id);
            $this->db->delete('crazy_sort'); 
        }

    }

?>
